package com.zggk.lzz.land;

import android.app.Activity;

import com.alibaba.fastjson.JSON;
import com.zggk.lzz.api.MyApplication;
import com.zggk.lzz.api.Urls;
import com.zggk.lzz.callback.StringDialogCallback;
import com.zggk.lzz.mvp.BasePresenterImpl;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class LandPresenter extends BasePresenterImpl<LandContract.View> implements LandContract.Presenter{
    @Override
    public void Land(String landJsons, Activity Activity) {
        OkGo.<String>post(Urls.LANDSERVER+"basic/apis/v1/auth/login")
                .params("user", landJsons)
                .execute(new StringDialogCallback(Activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LandBean landBean = JSON.parseObject(response.body(),LandBean.class);
                        if (mView == null)
                            return;
                        if (landBean.getCode()==200){
                            MyApplication.spUtils.put("Token", landBean.getData().getToken());
                            mView.getLand(landBean.getData());
                        }else {
                            mView.onRequestError(landBean.getMsg());
                        }
                    }
                });
    }
    @Override
    public void getUserInfo() {
        OkGo.<String>post(Urls.JAVASERVER + "pms/rhms/lzzapp/getuserinfo")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(final Response<String> response) {
                        mView.getUserInfos(response.body().toString());

                    }
                    @Override
                    public void onError(Response<String> response) {
                        mView.onRequestError("加载中...");
                    }
                });
    }
}
